package com.starry.module.system.core.dict.controller.admin;

import cn.hutool.http.HttpStatus;
import com.starry.core.common.domain.R;
import com.starry.core.common.domain.vo.PageVo;
import com.starry.core.web.core.controller.BaseController;
import com.starry.module.system.api.dict.domain.qo.SysDictionaryPageQo;
import com.starry.module.system.api.dict.domain.qo.SysDictionaryQo;
import com.starry.module.system.api.dict.domain.vo.SysDictionaryDtlVo;
import com.starry.module.system.api.dict.domain.vo.SysDictionaryVo;
import com.starry.module.system.core.dict.service.SysDictionaryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
 * 系统字典
 *
 * @author xiaoke
 */
@Tag(name = "系统字典")
@RestController
@RequestMapping("/system/sysDictionary")
public class SysDictionaryController extends BaseController {

    private final SysDictionaryService sysDictionaryService;

    public SysDictionaryController(SysDictionaryService sysDictionaryService) {
        this.sysDictionaryService = sysDictionaryService;
    }

    /**
     * 分页查询
     *
     * @param pageQo 查询实体
     * @return 所有数据
     */
    @Operation(summary = "系统字典-分页查询")
    @GetMapping("sysDictionaryPage")
    public R<PageVo<SysDictionaryVo>> findPage(SysDictionaryPageQo pageQo) {
        return success(this.sysDictionaryService.page(pageQo));
    }

    /**
     * 详情
     *
     * @param id 主键
     * @return 单条数据
     */
    @Operation(summary = "系统字典-详情")
    @GetMapping("sysDictionaryDetails/{id}")
    public R<SysDictionaryDtlVo> findById(@PathVariable("id") Long id) {
        return success(this.sysDictionaryService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param sysDictionaryQo 实体对象
     * @return 新增结果
     */
    @Operation(summary = "系统字典-新增")
    @PostMapping("sysDictionaryCreate")
    public R<Long> insert(@RequestBody @Validated SysDictionaryQo sysDictionaryQo) {
        return success(HttpStatus.HTTP_CREATED, this.sysDictionaryService.save(sysDictionaryQo));
    }

    /**
     * 修改数据
     *
     * @param sysDictionaryQo 实体对象
     * @return 修改结果
     */
    @Operation(summary = "系统字典-修改")
    @PostMapping("sysDictionaryUpdate")
    public R<Void> update(@RequestBody @Validated SysDictionaryQo sysDictionaryQo) {
        this.sysDictionaryService.updateById(sysDictionaryQo);
        return success();
    }

    /**
     * 删除数据
     *
     * @param idList 主键集合
     * @return Void
     */
    @Operation(summary = "系统字典-删除")
    @PostMapping("sysDictionaryRemove")
    public R<Void> delete(@RequestParam("idList") Set<Long> idList) {
        this.sysDictionaryService.removeByIds(idList);
        return success();
    }

    /**
     * 启用数据
     *
     * @param idList 主键集合
     * @return Void
     */
    @Operation(summary = "系统字典-启用")
    @PostMapping("sysDictionaryEnable")
    public R<Void> enable(@RequestParam("idList") Set<Long> idList) {
        this.sysDictionaryService.enable(idList);
        return success();
    }

    /**
     * 禁用数据
     *
     * @param idList 主键集合
     * @return Void
     */
    @Operation(summary = "系统字典-禁用")
    @PostMapping("sysDictionaryDisable")
    public R<Void> disable(@RequestParam("idList") Set<Long> idList) {
        this.sysDictionaryService.disable(idList);
        return success();
    }
}

